#!/bin/bash

set -e

source "$(
  cd "$(dirname "$0")" || exit 1
  pwd
)/../common.sh"

#下载依赖和工具包
function install_development() {

  source /etc/profile
}

#获取TensorRT-GA
function download_TensorRT-GA() {
  echo "# TensorRT-GA正在拷贝"
  cp  "$2"/src/TensorRT-8.2.0.6.Ubuntu-20.04.aarch64-gnu.cuda-11.4.cudnn8.2.tar.gz  "$1" 
  if [[ $? -eq 0 ]]; then
    echo -e "\033[1;32;1m# TensorRT-GA-8.2.0.6拷贝成功\033[0m"
  else
    echo -e "\033[31m# TensorRT-GA-8.2.0.6拷贝失败,请重新执行脚本\033[0m"
    exit 1
  fi
}

function install_TensorRT-GA() {
  echo "# TensorRT-GA正在安装"
  tar -zxvf "$1"/TensorRT-8.2.0.6.Ubuntu-20.04.aarch64-gnu.cuda-11.4.cudnn8.2.tar.gz -C "$2" && rm -rf "$1"/TensorRT-8.2.0.6.Ubuntu-20.04.aarch64-gnu.cuda-11.4.cudnn8.2.tar.gz
  echo -e "\033[1;32;1m# TensorRT-GA已经解压完毕\033[0m"
}


function main() {
    install_development
    download_TensorRT-GA "$1" "$4"
    install_TensorRT-GA "$1" "$2"
}

main "$@"